
import { Navigate } from "react-router-dom";
import Login from '../pages/Login'
import React from "react";
import lazyLoad from "./utils/lazyLoad";
import Layout from '@/components/Layout/Layout'
import Home from '@mui/icons-material/Home';

// * 导入所有router
const modulesFiles = require.context('./modules', true, /\.jsx$/);

// * 处理路由
export const routerArray = [];
modulesFiles.keys().forEach(modulePath => {
  const value = modulesFiles(modulePath)
  routerArray.push(...value.default)
})
export const PAGES = [
  {
		path: "/",
		element: <Navigate to="/login" />
	},
  {
		path: "/login",
		element: <Login />,
		meta: {
			requiresAuth: false,
			key: "login",
      title: "登录页",
		}
	},
  {
    element: <Layout />,
    children: [
      {
        path: '/index',
        element: lazyLoad(React.lazy(() => import("@/pages/HomePage"))),
        meta: {
          requiresAuth: true,
          key: "homePage",
          title: "首页",
          icon: Home,
          titleI18n: 'homePage',
          showNav: true
        },
        index: 1
      }
    ]
  },
  ...routerArray,
  {
		path: "*",
		element: <Navigate to="/404" />
	}
];

export const allRouters = [
  {
    element: <Layout />,
    children: [
      {
        path: '/index',
        element: lazyLoad(React.lazy(() => import("@/pages/HomePage"))),
        meta: {
          requiresAuth: true,
          key: "homePage",
          title: "首页",
          icon: Home,
          titleI18n: 'homePage',
          showNav: true
        },
        index: 1
      }
    ]
  },
  ...routerArray
]
